import java.awt.*;
import java.awt.event.*;

import javax.swing.*;

public class Dashboard extends JPanel implements ActionListener {

	private JButton bComp, bEmp, bGrade, bRep, bSec, bLogout;
	private static JLabel lName;
	private String sFirst = "Tekki", sLast = "Ebora";
	private static int choice;
	

	private ImageIcon iComp = new ImageIcon("gui/buttons/homeComp.png"),
	 				  iComp_ = new ImageIcon("gui/buttons/homeComp_.png"),
	  				  iEmp = new ImageIcon("gui/buttons/homeEmp.png"),
	                  iEmp_ = new ImageIcon("gui/buttons/homeEmp_.png"),
	  				  iGrade = new ImageIcon("gui/buttons/homeGrade.png"),
	  				  iGrade_ = new ImageIcon("gui/buttons/homeGrade_.png"),
	  				  iRep = new ImageIcon("gui/buttons/homeRep.png"),
	  				  iRep_ = new ImageIcon("gui/buttons/homeRep_.png"),
	  				  iSec = new ImageIcon("gui/buttons/homeSec.png"),
	  				  iSec_ = new ImageIcon("gui/buttons/homeSec_.png");
	
	public Dashboard(){
		setLayout(null);
		setBounds(0,0,700,600);	
		setOpaque(false);

		createGUI();
	}

	public void actionPerformed(ActionEvent a) {
		if(a.getSource() == bLogout){
			Object[] options = {"Yes","No"};
			choice = JOptionPane.showOptionDialog(null,"Are you sure you want to end your session?","LSQC Grading System Software",JOptionPane.YES_NO_OPTION,JOptionPane.WARNING_MESSAGE,null,options,options[0]);
			System.out.println(choice);
			if(choice == 0) {
				MainPanel.goToPage(0);
				MainPanel.setUserType(-1);
			}
		}
		else if(a.getSource() == bEmp){
			MainPanel.goToPage(2);
		}
		else if(a.getSource() == bSec){
			MainPanel.goToPage(3);
		}
		else if(a.getSource() == bGrade){
			MainPanel.goToPage(5);
		}
		else if(a.getSource() == bComp){
			MainPanel.goToPage(7);
		}
	}
	
	public void createGUI(){
		bComp = new JButton(iComp);
		bComp.setBounds(350,320,302,119);
		bComp.setRolloverIcon(iComp_);
		bComp.setBorderPainted(false);
		bComp.setContentAreaFilled(false);
		bComp.setVisible(false);
		bComp.addActionListener(this);
		add(bComp);
		
		bEmp = new JButton(iEmp);
		bEmp.setBounds(350,80,302,119);
		bEmp.setRolloverIcon(iEmp_);
		bEmp.setBorderPainted(false);
		bEmp.setContentAreaFilled(false);
		bEmp.setVisible(false);
		bEmp.addActionListener(this);
		add(bEmp);

		bGrade = new JButton(iGrade);
		bGrade.setBounds(350,80,302,119);
		bGrade.setRolloverIcon(iGrade_);
		bGrade.setBorderPainted(false);
		bGrade.setContentAreaFilled(false);
		bGrade.setVisible(false);
		bGrade.addActionListener(this);
		add(bGrade);

		bRep = new JButton(iRep);
		bRep.setBounds(350,440,302,119);
		bRep.setRolloverIcon(iRep_);
		bRep.setBorderPainted(false);
		bRep.setToolTipText("Page not yet done. This module will completely depend on the database. Sorry for the inconvenience.");
		bRep.setContentAreaFilled(false);
		bRep.addActionListener(this);
		add(bRep);

		bSec = new JButton(iSec);
		bSec.setBounds(350,200,302,119);
		bSec.setRolloverIcon(iSec_);
		bSec.setBorderPainted(false);
		bSec.setContentAreaFilled(false);
		bSec.setVisible(false);
		bSec.addActionListener(this);
		add(bSec);
		
		lName = new JLabel(sLast+", "+sFirst+"!", JLabel.CENTER);
		lName.setFont(new Font("Lucida Grande", Font.BOLD, 16));
		lName.setForeground(Color.black);
		lName.setBounds(10,460,300,30);
		add(lName);
		
		bLogout = new JButton("Logout");
		bLogout.setBounds(20,550,120,30);
		bLogout.addActionListener(this);
		add(bLogout);
	}
	
	public void refreshGUI(){
		if(MainPanel.getUserType() == 0){
			bComp.setVisible(true);
			bEmp.setVisible(true);
			bGrade.setVisible(false);
			bSec.setVisible(true);
			bRep.setBounds(350,440,302,119);
			MainPanel.bg.changeCurrentImage(1);
		}
		else if(MainPanel.getUserType() > 0) {
			bComp.setVisible(false);
			bEmp.setVisible(false);
			bGrade.setVisible(true);
			bSec.setVisible(false);
			bRep.setBounds(350,200,302,119);
			MainPanel.bg.changeCurrentImage(1);
		}
	}
}